﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ModuleDALCore;
using DTO;

namespace DAL
{
	public class LYDOBIETNHAKHOADAO:DALBase
	{
		public LYDOBIETNHAKHOADAO()
		{
			this.OpenConnect();
		}
		private DataTable dt;
		private string _SpName;

		public string SpName
		{
			get { return "SPLYDOBIETNHAKHOA"; }
			set { _SpName = value; }
		}
		public DataTable GetListLD()
		{
			dt = new DataTable();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new LYDOBIETNHAKHOA(), null), ConvertClassToArray.GetValues(new LYDOBIETNHAKHOA(), 0));
				return dt;
			}
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't list LD"); }
		}
		public List<LYDOBIETNHAKHOA> GetListLDs()
		{
			dt = new DataTable();
			List<LYDOBIETNHAKHOA> ds = new List<LYDOBIETNHAKHOA>();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new LYDOBIETNHAKHOA(), null), ConvertClassToArray.GetValues(new LYDOBIETNHAKHOA(), 0));
				ds = (List<LYDOBIETNHAKHOA>)ConvertDatatableToList.ConvertTo<LYDOBIETNHAKHOA>(dt);
			}
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't list LD"); }
			return ds;
		}
		public String CreatenewId()
		{
			try
			{
				return "LD" + DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(new LYDOBIETNHAKHOA(), null), ConvertClassToArray.GetValues(new LYDOBIETNHAKHOA(), 1));

			}
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't Create new LD"); }
		}
		public bool INSERT(LYDOBIETNHAKHOA cv)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 2)) == 1);

			}
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Insert new LD"); }
		}
		public bool UPDATE(LYDOBIETNHAKHOA cv)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 3)) == 1);

			}
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Update  LD"); }
		}
		public bool DELETE(LYDOBIETNHAKHOA cv)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 4)) == 1);

			}
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Delete  LD"); }
		}
		public bool UPDATECARD(LYDOBIETNHAKHOA cv)
		{
			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 5)) == 1);

			}
			catch { return false; }//throw new InvalidExpressionException("Msg1: CAN'T UPDATE CRARD"); }
		}
		public LYDOBIETNHAKHOA GETLYDOTHEOBN(LYDOBIETNHAKHOA ld)
		{
			dt = new DataTable();
			LYDOBIETNHAKHOA ds = new LYDOBIETNHAKHOA();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(ld, null), ConvertClassToArray.GetValues(ld, 6));
				ds = (LYDOBIETNHAKHOA)ConvertDatatableToList.ConvertToObject<LYDOBIETNHAKHOA>(dt);
			}
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't list LD"); }
			return ds;
		} 
	
	}
}
